// pages/searchSchool/index.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navHeight: app.globalData.statusBarHeight * 2 + 86,
        value: '',
        schoolList:[],
        pageIndex: 1,
        pageCount: 10,
        templId:'',
        schoolKey:'',
        show:false,
        schoolValue:'',
        queueId:''
    },
    onSchoolChange(event) {
        this.setData({
            schoolValue:event.detail
        })
        console.log(event.detail);
      },
      showAdd(){
         this.setData({
             show:true,
             schoolValue:''
         })
      },
      add(event) {
          console.log('event',event)
        let that= this
        let param={
            deptId:app.globalData.deptId,
            name:this.data.schoolValue
           }
        wx.request({
            url: app.getUrl('/xcx/pt/insertNursery'),
            method: 'POST',
            data:param,
            success(res) {
                console.log('res',res)
                console.log('res rows',JSON.parse(res.data.data) )
                if (res.data.code == 0) {
                    let msg= JSON.parse(res.data.data).msg
                    wx.showToast({
                      title: '添加成功',
                    })
                  that.setData({
                    value:that.data.schoolValue
                  })
                  that.getNursery()
                }
            }
        })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('options',options)
      this.setData({
        templId:options.templId,
        schoolKey:options.schoolKey,
        queueId:options.queueId
      })
    },
    onChange(e) {
        this.setData({
          value: e.detail,
        });
      },
    onSearch(){
       console.log('e',this.data.value)
       console.log('app',app.globalData)
       this.getNursery()
    },
    getNursery(){
        let that = this
        let param={
            deptId:app.globalData.deptId,
            name:this.data.value||'幼儿园'
           }
        wx.request({
            url: app.getUrl('/xcx/pt/queryNursery'),
            method: 'POST',
            data:param,
            success(res) {
                console.log('res',res)
                console.log('res rows',JSON.parse(res.data.data) )
                if (res.data.code == 0) {
                        that.setData({
                            schoolList: JSON.parse(res.data.data).rows,
                            pageCount: JSON.parse(res.data.data).total
                        })
                }
            }
        })
    },
    toCreateArchive(e){
      console.log('ee222',e)
      wx.navigateTo({
        url: `/pages/archive/newArchive?schoolName=${e.currentTarget.dataset.category.name}&templId=${this.data.templId}&schoolKey=${this.data.schoolKey}&queueId=${this.data.queueId}`    
      })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getNursery()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})